﻿using System;
using System.Web.Mvc;

namespace WebStudio_Site_MVC.Areas.Admin
{
    public class AdminAreaRegistration : AreaRegistration
    {
        /// <summary>
        /// 区域名称
        /// </summary>
        public override string AreaName
        {
            get
            {
                return "Admin";
            }
        }

        /// <summary>
        /// 注册区域路由
        /// </summary>
        /// <param name="context"></param>
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.Routes.IgnoreRoute("{resource}.js/{*pathInfo}");

            //获取IIS版本
            var iisVersion = WebStudio.Mvc.Core.Helper.ServerHelper.GetIISVersion();
            if (iisVersion != WebStudio.Mvc.Core.Helper.IISVersion.IIS7)
            {
                //注册IIS6路由
                context.MapRoute("Admin_NoAction", "Admin/{controller}.aspx", new { controller = "Admin", action = "Index", id = UrlParameter.Optional });//无Action的匹配
                context.MapRoute("Admin_NoID", "Admin/{controller}/{action}.aspx", new { controller = "Admin", action = "Index", id = UrlParameter.Optional });//无ID的匹配
                context.MapRoute("Admin_default", "Admin/{controller}/{action}/{id}.aspx", new { controller = "Admin", action = "Index" });//默认匹配
                context.MapRoute("Admin_root", "Admin.aspx", new { controller = "Admin", action = "Index", id = UrlParameter.Optional });//根目录匹配
            }
            else
            {
                //注册IIS7路由
                context.MapRoute(
                    "Admin_default",
                    "Admin/{controller}/{action}/{id}",
                    new { controller = "Main",  id = UrlParameter.Optional }
                );
            } 
        }
    }
}
